﻿Imports System.Threading

Public Class frmWaitingDialog
    Private Shared _waitingThread As Thread
    Private Shared _waitingDialog As frmWaitingDialog

    Public Sub New(message As String)

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        radWaitingBarMain.StartWaiting()
    End Sub

    Public Shared Sub ShowDialogForWaiting(message As String)
        Dim ThreadStart As ParameterizedThreadStart = New ParameterizedThreadStart(AddressOf LaunchDialog)
        _waitingThread = New Thread(ThreadStart)
        _waitingThread.IsBackground = True
        _waitingThread.Start(message)
    End Sub

    Private Shared Sub LaunchDialog(message As Object)
        _waitingDialog = New frmWaitingDialog(message.ToString())

        ''//Create New message pump 
        Application.Run(_waitingDialog)
    End Sub

    Private Shared Sub CloseDialogDown()
        Application.ExitThread()
    End Sub

    Public Shared Sub CloseDialog()
        If _waitingDialog IsNot Nothing Then
            Try
                Dim mi As MethodInvoker = New MethodInvoker(AddressOf CloseDialogDown)
                _waitingDialog.Invoke(mi)
            Catch ex As Exception
            End Try
        End If
    End Sub


    Private Sub FrmWait_Load(sender As Object, e As EventArgs) Handles MyBase.Load


        Me.BackColor = Color.White
        Me.TransparencyKey = Color.White
        Me.ShowInTaskbar = False
    End Sub
End Class
